package org.jsola.hr.helper;

import org.jsola.common.DateKit;
import org.jsola.common.SafeKit;
import org.jsola.hr.dto.SalaryCycleAddDTO;
import org.jsola.hr.dto.SalaryCycleUpdateDTO;
import org.jsola.hr.entity.SalaryCycleDO;
import org.jsola.hr.query.SalaryCycleQuery;
import org.jsola.hr.service.ISalaryCycleService;
import org.jsola.hr.vo.SalaryCycleVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * @author zhr
 */
@Component
public class SalaryCycleTestHelper extends BaseTestHelper {
    
    @Autowired
    private ISalaryCycleService salaryCycleService;

    /**
     * 生成add测试数据
     * @return SalaryCycleAddDTO
     */
    public SalaryCycleAddDTO getSalaryCycleAddDTO(){
        SalaryCycleAddDTO salaryCycleAddDTO = new SalaryCycleAddDTO();
        salaryCycleAddDTO.setPayMonth(SafeKit.getInteger(getRandomValue("tinyint",4)));
        salaryCycleAddDTO.setPayDate(SafeKit.getInteger(getRandomValue("int",11)));
        salaryCycleAddDTO.setSocMonth(SafeKit.getInteger(getRandomValue("tinyint",4)));
        salaryCycleAddDTO.setSocDataSource(SafeKit.getInteger(getRandomValue("tinyint",4)));
        salaryCycleAddDTO.setAttendanceDataSource(SafeKit.getInteger(getRandomValue("tinyint",4)));
        salaryCycleAddDTO.setAttendanceModuleItem(SafeKit.getInteger(getRandomValue("tinyint",4)));
        salaryCycleAddDTO.setLeaveDownsizing(SafeKit.getInteger(getRandomValue("tinyint",4)));
        salaryCycleAddDTO.setCompanyId(getRandomValue("varchar",32));
        return salaryCycleAddDTO;
    }


    /**
     * 生成update测试数据
     * @return SalaryCycleUpdateDTO
     */
    public SalaryCycleUpdateDTO getSalaryCycleUpdateDTO(SalaryCycleVO salaryCycleVO){
        return salaryCycleService.selectDOById(salaryCycleVO.getId(), SITE_ID).to(SalaryCycleUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return SalaryCycleQuery
     */
    public SalaryCycleQuery getSalaryCycleQuery() {
        SalaryCycleQuery salaryCycleQuery = new SalaryCycleQuery();
        List<SalaryCycleDO> salaryCycleDOList = salaryCycleService.list(new SalaryCycleDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(salaryCycleDOList)) {
            SalaryCycleDO salaryCycleDO = salaryCycleDOList.get(0);
            salaryCycleQuery = salaryCycleDO.to(SalaryCycleQuery.class);
            if (salaryCycleDO.getGmtCreate() != null) {
                salaryCycleQuery.setGmtCreateStart(DateKit.getBeforeDay(salaryCycleDO.getGmtCreate(),-1));
                salaryCycleQuery.setGmtCreateEnd(DateKit.getBeforeDay(salaryCycleDO.getGmtCreate(),1));
            }
            if (salaryCycleDO.getGmtModified() != null) {
                salaryCycleQuery.setGmtModifiedStart(DateKit.getBeforeDay(salaryCycleDO.getGmtModified(),-1));
                salaryCycleQuery.setGmtModifiedEnd(DateKit.getBeforeDay(salaryCycleDO.getGmtModified(),1));
            }
        }
        return salaryCycleQuery;
    }

    /**
     * 保存示例
     * @return SalaryCycleVO
     */
    public SalaryCycleVO saveSalaryCycleExample(){
        SalaryCycleAddDTO addDTO = this.getSalaryCycleAddDTO();
        SalaryCycleVO salaryCycleVO = salaryCycleService.save(addDTO,buildTokenUser());
        return salaryCycleVO;
    }


}

